<?php
/**
 * XmlRpc编码抽象类
 *
 * @version $Id: AbstractXmlRpcEncoder.php 312 2008-04-23 16:29:38Z iwind $
 * @package net.4kiki.rai.format.xmlrpc.encoder
 * @since 0.0.3
 */
abstract class AbstractXmlRpcEncoder implements XmlRpcEncoder {
	private $phpVar;
	private $charset;
	
	/**
	 * 构造器
	 *
	 * @param mixed $phpVar PHP变量
	 * @param string $charset 字符集
	 */
	public function __construct($phpVar, $charset = "UTF-8") {
		$this->phpVar = $phpVar;
		$this->charset = $charset;
	}
	
	/**
	 * 取得变量
	 *
	 * @return mixed
	 */
	public function getVar() {
		return $this->phpVar;
	}
	
	/**
	 * 取得字符集
	 *
	 * @return string
	 */
	public function getCharset() {
		return $this->charset;
	}
	
	/**
	 * 转换为XML字符串
	 *
	 * @return unknown
	 */
	public function asXmlString() {
		$xml = $this->asDOM()->saveXML();
		return preg_replace("/^<\?xml.+\?>/sU", "", ltrim($xml));
	}
	
	/**
	 * 将对象转换为DOMDocument
	 *
	 * @return DOMDocument
	 */
	public abstract function asDOM();
}

?>